/**
 * 
 */
package com.trungsi.profile;

import java.io.File;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author trand
 *
 */
public class SimpleTracePrinter implements TracePrinter {

	private String logDir;
	private String fileName;
	private PrintWriter printer;
	
	public SimpleTracePrinter() {
		this.logDir = System.getProperty("profile.printer.dir", ".");
		this.fileName = System.getProperty("profile.printer.filename", "profile");
		initPrinter();
	}
	
	private void initPrinter() {
		try {
			printer = new PrintWriter(new File(logDir, fileName + "-" + format(new Date()) + ".txt"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	private String format(Date date) {
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd-HHmmss");
		return format.format(date);
	}

	/* (non-Javadoc)
	 * @see com.trungsi.profile.TracePrinter#print(com.trungsi.profile.Call)
	 */
	public void print(Call call) {
		call.print(printer);
	}

}
